gl: Use the appropriate format on GLES
authorEmmanuele Bassi <ebassi@gnome.org>
Sat, 23 Apr 2016 09:21:13 +0000 (10:21 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 25 Apr 2016 11:29:36 +0000 (12:29 +0100)
When uploading a Cairo image surface to a GL texture we cannot use
GL_BGRA and GL_UNSIGNED_INT_8_8_8_8_REV on OpenGL ES, as they do not
exist in the core spec.

gdk/gdkglcontext.c

index 8eb39f11971073e12d49258c83d969087bc34da4..ca29955848d3c6381d1381af8d40946c8e63adcd 100644 (file)
@@ -248,12 +248,20 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
   /* GL_UNPACK_ROW_LENGTH is available on desktop GL, OpenGL ES >= 3.0, or if
    * the GL_EXT_unpack_subimage extension for OpenGL ES 2.0 is available
    */
-  if (epoxy_is_desktop_gl () || priv->gl_version >= 30 || priv->has_unpack_subimage)
+  if (!gdk_gl_context_get_use_es (context) ||
+      (gdk_gl_context_get_use_es (context) &&
+       (priv->gl_version >= 30 || priv->has_unpack_subimage)))
     {
       glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
       glPixelStorei (GL_UNPACK_ROW_LENGTH, cairo_image_surface_get_stride (image_surface) / 4);
-      glTexImage2D (texture_target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
-                    cairo_image_surface_get_data (image_surface));
+
+      if (gdk_gl_context_get_use_es (context))
+        glTexImage2D (texture_target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+                      cairo_image_surface_get_data (image_surface));
+      else
+        glTexImage2D (texture_target, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
+                      cairo_image_surface_get_data (image_surface));
+
       glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
     }
   else